package com.gobang.common.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 业务错误码枚举
 * 
 * 错误码规范：
 * - 1xxxx: 通用错误码
 * - 2xxxx: 用户管理模块
 * - 3xxxx: 用户资料模块
 * - 4xxxx: 积分管理模块
 * - 5xxxx: 匹配系统模块
 * - 6xxxx: 游戏房间模块
 * - 7xxxx: 游戏逻辑模块
 * - 8xxxx: 网络通信模块
 * - 9xxxx: 对局记录模块
 * 
 * @author Gobang Team
 * @version 1.0.0
 */
@Getter
@AllArgsConstructor
public enum BusinessErrorCode implements ErrorCode {

    // ==================== 通用错误码 (1xxxx) ====================
    SUCCESS(200, "操作成功"),
    SYSTEM_ERROR(10000, "系统异常"),
    PARAM_ERROR(10001, "参数错误"),
    PARAM_MISSING(10002, "参数缺失"),
    PARAM_INVALID(10003, "参数格式不正确"),
    REQUEST_METHOD_NOT_SUPPORTED(10004, "请求方法不支持"),
    REQUEST_NOT_READABLE(10005, "请求体无法读取"),
    RESOURCE_NOT_FOUND(10006, "资源不存在"),
    UNAUTHORIZED(10007, "未授权访问"),
    FORBIDDEN(10008, "禁止访问"),
    TOO_MANY_REQUESTS(10009, "请求过于频繁，请稍后再试"),
    SERVICE_UNAVAILABLE(10010, "服务暂时不可用"),

    // ==================== 用户管理模块 (2xxxx) ====================
    USER_NOT_FOUND(20001, "用户不存在"),
    USER_ALREADY_EXISTS(20002, "账号已存在"),
    USERNAME_INVALID(20003, "用户名格式不正确"),
    PASSWORD_INVALID(20004, "密码格式不正确"),
    PASSWORD_WRONG(20005, "密码错误"),
    PASSWORD_CONFIRM_WRONG(20006,"两次输入的密码不一致"),
    PASSWORD_TOO_SHORT(20007, "密码长度不能少于8位"),
    PASSWORD_TOO_SIMPLE(20008, "密码必须包含字母和数字"),
    TOKEN_INVALID(20009, "Token无效"),
    TOKEN_EXPIRED(200010, "Token已过期"),
    TOKEN_MISSING(20011, "Token缺失"),
    USER_DISABLED(20012, "用户已被禁用"),
    USER_LOCKED(20013, "用户已被锁定"),
    LOGIN_FAILED(20014, "登录失败"),
    LOGOUT_FAILED(20015, "退出登录失败"),
    USER_ALREADY_ONLINE(20016, "用户已在线，不能重复登录"),
    USER_NOT_ONLINE(20017, "用户未在线"),
    USER_REGISTER_FAIL(20018,"用户注册失败"),

    // ==================== 用户资料模块 (3xxxx) ====================
    PROFILE_NOT_FOUND(30001, "用户资料不存在"),
    DISPLAY_NAME_INVALID(30002, "显示昵称格式不正确"),
    DISPLAY_NAME_TOO_LONG(30003, "显示昵称长度不能超过20个字符"),
    DISPLAY_NAME_ALREADY_EXISTS(30004, "显示昵称已被使用"),
    PROFILE_UPDATE_FAILED(30005, "用户资料更新失败"),
    PROFILE_CREATE_FAILED(30006, "用户资料创建失败"),

    // ==================== 积分管理模块 (4xxxx) ====================
    POINTS_ACCOUNT_NOT_FOUND(40001, "积分账户不存在"),
    POINTS_INSUFFICIENT(40002, "积分不足"),
    POINTS_CANNOT_BE_NEGATIVE(40003, "积分不能为负数"),
    POINTS_UPDATE_FAILED(40004, "积分更新失败"),
    POINTS_LOG_NOT_FOUND(40005, "积分流水不存在"),
    POINTS_LOG_CREATE_FAILED(40006, "积分流水创建失败"),
    POINTS_DELTA_INVALID(40007, "积分变更值不合法"),
    POINTS_CONCURRENT_UPDATE(40008, "积分更新冲突，请重试"),

    // ==================== 匹配系统模块 (5xxxx) ====================
    MATCH_ALREADY_IN_QUEUE(50001, "您已在匹配队列中"),
    MATCH_NOT_IN_QUEUE(50002, "您不在匹配队列中"),
    MATCH_TIMEOUT(50003, "匹配超时"),
    MATCH_CANCEL_FAILED(50004, "取消匹配失败"),
    MATCH_JOIN_FAILED(50005, "加入匹配队列失败"),
    MATCH_OPPONENT_NOT_FOUND(50006, "未找到合适的对手"),
    MATCH_USER_IN_GAME(50007, "您正在游戏中，无法进行匹配"),
    MATCH_USER_OFFLINE(50008, "用户已离线，匹配取消"),

    // ==================== 游戏房间模块 (6xxxx) ====================
    ROOM_NOT_FOUND(60001, "游戏房间不存在"),
    ROOM_ALREADY_FULL(60002, "游戏房间已满"),
    ROOM_NOT_STARTED(60003, "游戏尚未开始"),
    ROOM_ALREADY_STARTED(60004, "游戏已经开始"),
    ROOM_ALREADY_FINISHED(60005, "游戏已结束"),
    ROOM_CREATE_FAILED(60006, "创建房间失败"),
    ROOM_JOIN_FAILED(60007, "加入房间失败"),
    ROOM_LEAVE_FAILED(60008, "离开房间失败"),
    ROOM_STATUS_ERROR(60009, "房间状态异常"),
    USER_NOT_IN_ROOM(60010, "您不在该房间中"),
    USER_ALREADY_IN_ROOM(60011, "您已在其他房间中"),

    // ==================== 游戏逻辑模块 (7xxxx) ====================
    GAME_NOT_STARTED(70001, "游戏尚未开始"),
    GAME_ALREADY_FINISHED(70002, "游戏已结束"),
    MOVE_INVALID(70003, "落子位置不合法"),
    MOVE_OUT_OF_BOARD(70004, "落子超出棋盘范围"),
    MOVE_POSITION_OCCUPIED(70005, "该位置已有棋子"),
    NOT_YOUR_TURN(70006, "当前不是您的回合"),
    SURRENDER_FAILED(70007, "认输失败"),
    GAME_RESULT_SAVE_FAILED(70008, "游戏结果保存失败"),
    TIMER_EXPIRED(70009, "思考时间已用完"),
    BOARD_STATE_ERROR(70010, "棋盘状态异常"),
    GAME_LOGIC_ERROR(70011, "游戏逻辑错误"),
    PLAYER_ROLE_ERROR(70012, "玩家角色错误"),

    // ==================== 网络通信模块 (8xxxx) ====================
    WEBSOCKET_CONNECT_FAILED(80001, "WebSocket连接失败"),
    WEBSOCKET_DISCONNECT_FAILED(80002, "WebSocket断开失败"),
    WEBSOCKET_SEND_FAILED(80003, "消息发送失败"),
    WEBSOCKET_SESSION_NOT_FOUND(80004, "WebSocket会话不存在"),
    WEBSOCKET_MESSAGE_FORMAT_ERROR(80005, "消息格式错误"),
    WEBSOCKET_HEARTBEAT_TIMEOUT(80006, "心跳超时"),
    WEBSOCKET_RECONNECT_FAILED(80007, "重连失败"),
    WEBSOCKET_RECONNECT_TOKEN_INVALID(80008, "重连令牌无效"),

    // ==================== 对局记录模块 (9xxxx) ====================
    MATCH_RECORD_NOT_FOUND(90001, "对局记录不存在"),
    MATCH_RECORD_CREATE_FAILED(90002, "创建对局记录失败"),
    MATCH_RECORD_UPDATE_FAILED(90003, "更新对局记录失败"),
    MATCH_RECORD_QUERY_FAILED(90004, "查询对局记录失败");

    /**
     * 错误码
     */
    private final Integer code;

    /**
     * 错误消息
     */
    private final String message;

}

